import { success } from '../common/ResResult'
import { Context } from 'koa'
import { get, post } from '../decorator/reqmethoddecorator'
import searchService from '../modules/search/service/SearchService'
import { Controller } from '../decorator/controllerdecorator'
// TS 装饰器 重构Koa 路由中的方法装饰器
@Controller('/searchmodule')
class SearchController {
  @post('/addOrUpdateHistoryKeyword')
  async addOrUpdateHistoryKeyword(ctx: Context) {
    const { historyKeyword } = ctx.request.body;
    const result = await searchService.addOrUpdateHistoryKeyword(historyKeyword);
    ctx.body = success(result);
  }
  @get('/searchKeywords/:key')
  async searchKeywords(ctx: Context) {
    const { key } = ctx.params;
    const keywordlist =  await searchService.SearchKeywords(key);
    ctx.body = success(keywordlist);
  }
  @get('/searchDecovery')
  async searchDecovery (ctx: Context) {
    const keywordlist =  await searchService.searchDecovery();
    ctx.body = success(keywordlist);
  }
}
